<?php
/*
  $Id: stats_batch_report.php,v 1.0 2006/08/28 15:03:59 $
  
  contributed by Brian Berry <brian@jdbtech.com>


  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2002 osCommerce

  Released under the GNU General Public License
*/

  require('includes/application_top.php');

  require(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new currencies();

  if ($HTTP_GET_VARS['month'] == '') 
  {
    $day1=date("d");
  	$month = date("m");
    $year = '20' . date("y");

    $date1=$year."-".$month."-".$day1;
    
    $day22 = date("d");
    $month22 = date("m");
    $year22 = '20'. date("y");
    
    
    $date2=$year22."-".$month22."-".$day22;
   // echo $date1."<br>";
   //echo $date2;

    
    
  } else 
  {
    $day1 = $HTTP_GET_VARS['day'];
    $month = $HTTP_GET_VARS['month'];
    $year = $HTTP_GET_VARS['year'];
     
    $date1=$year."-".$month."-".$day1;
    
    $day22 = $HTTP_GET_VARS['day2'];
    $month22 = $HTTP_GET_VARS['month2'];
    $year22 = $HTTP_GET_VARS['year2'];
        
    $date2=$year22."-".$month22."-".$day22;
    
   // echo $date1."<br>";
   // echo $date2;

    
  }
  
  $months = array();
  $months[] = array('id' => 1, 'text' => 'January');
  $months[] = array('id' => 2, 'text' => 'February');
  $months[] = array('id' => 3, 'text' => 'March');
  $months[] = array('id' => 4, 'text' => 'April');
  $months[] = array('id' => 5, 'text' => 'May');
  $months[] = array('id' => 6, 'text' => 'June');
  $months[] = array('id' => 7, 'text' => 'July');
  $months[] = array('id' => 8, 'text' => 'August');
  $months[] = array('id' => 9, 'text' => 'September');
  $months[] = array('id' => 10, 'text' => 'October');
  $months[] = array('id' => 11, 'text' => 'November');
  $months[] = array('id' => 12, 'text' => 'December');


   $day = array();
   $day[] = array('id' => 1, 'text' => '1');
   $day[] = array('id' => 2, 'text' => '2');
   $day[] = array('id' => 3, 'text' => '3');
   $day[] = array('id' => 4, 'text' => '4');
   $day[] = array('id' => 5, 'text' => '5');
   $day[] = array('id' => 6, 'text' => '6');
   $day[] = array('id' => 7, 'text' => '7');
   $day[] = array('id' => 8, 'text' => '8');
   $day[] = array('id' => 9, 'text' => '9');
   $day[] = array('id' => 10, 'text' => '10');
   $day[] = array('id' => 11, 'text' => '11');
   $day[] = array('id' => 12, 'text' => '12');
   $day[] = array('id' => 13, 'text' => '13');
   $day[] = array('id' => 14, 'text' => '14');
   $day[] = array('id' => 15, 'text' => '15');
   $day[] = array('id' => 16, 'text' => '16');
   $day[] = array('id' => 17, 'text' => '17');
   $day[] = array('id' => 18, 'text' => '18');
   $day[] = array('id' => 19, 'text' => '19');
   $day[] = array('id' => 20, 'text' => '20');
   $day[] = array('id' => 21, 'text' => '21');
   $day[] = array('id' => 22, 'text' => '22');
   $day[] = array('id' => 23, 'text' => '23');
   $day[] = array('id' => 24, 'text' => '24');
   $day[] = array('id' => 25, 'text' => '25');
   $day[] = array('id' => 26, 'text' => '26');
   $day[] = array('id' => 27, 'text' => '27');
   $day[] = array('id' => 28, 'text' => '28');
   $day[] = array('id' => 29, 'text' => '29');
   $day[] = array('id' => 30, 'text' => '30');
   $day[] = array('id' => 31, 'text' => '31');
   
  

  $years = array();

  $years[] = array('id' => 2004, 'text' => '2004');
  $years[] = array('id' => 2005, 'text' => '2005');
  $years[] = array('id' => 2006, 'text' => '2006');
  $years[] = array('id' => 2007, 'text' => '2007');
  $years[] = array('id' => 2008, 'text' => '2008');
  $years[] = array('id' => 2009, 'text' => '2009');
  $years[] = array('id' => 2010, 'text' => '2010');
  $years[] = array('id' => 2011, 'text' => '2011');

  
    
  $months2 = array();
  $months2[] = array('id' => 1, 'text' => 'January');
  $months2[] = array('id' => 2, 'text' => 'February');
  $months2[] = array('id' => 3, 'text' => 'March');
  $months2[] = array('id' => 4, 'text' => 'April');
  $months2[] = array('id' => 5, 'text' => 'May');
  $months2[] = array('id' => 6, 'text' => 'June');
  $months2[] = array('id' => 7, 'text' => 'July');
  $months2[] = array('id' => 8, 'text' => 'August');
  $months2[] = array('id' => 9, 'text' => 'September');
  $months2[] = array('id' => 10, 'text' => 'October');
  $months2[] = array('id' => 11, 'text' => 'November');
  $months2[] = array('id' => 12, 'text' => 'December');

  
   $day2 = array();
   $day2[] = array('id' => 1, 'text' => '1');
   $day2[] = array('id' => 2, 'text' => '2');
   $day2[] = array('id' => 3, 'text' => '3');
   $day2[] = array('id' => 4, 'text' => '4');
   $day2[] = array('id' => 5, 'text' => '5');
   $day2[] = array('id' => 6, 'text' => '6');
   $day2[] = array('id' => 7, 'text' => '7');
   $day2[] = array('id' => 8, 'text' => '8');
   $day2[] = array('id' => 9, 'text' => '9');
   $day2[] = array('id' => 10, 'text' => '10');
   $day2[] = array('id' => 11, 'text' => '11');
   $day2[] = array('id' => 12, 'text' => '12');
   $day2[] = array('id' => 13, 'text' => '13');
   $day2[] = array('id' => 14, 'text' => '14');
   $day2[] = array('id' => 15, 'text' => '15');
   $day2[] = array('id' => 16, 'text' => '16');
   $day2[] = array('id' => 17, 'text' => '17');
   $day2[] = array('id' => 18, 'text' => '18');
   $day2[] = array('id' => 19, 'text' => '19');
   $day2[] = array('id' => 20, 'text' => '20');
   $day2[] = array('id' => 21, 'text' => '21');
   $day2[] = array('id' => 22, 'text' => '22');
   $day2[] = array('id' => 23, 'text' => '23');
   $day2[] = array('id' => 24, 'text' => '24');
   $day2[] = array('id' => 25, 'text' => '25');
   $day2[] = array('id' => 26, 'text' => '26');
   $day2[] = array('id' => 27, 'text' => '27');
   $day2[] = array('id' => 28, 'text' => '28');
   $day2[] = array('id' => 29, 'text' => '29');
   $day2[] = array('id' => 30, 'text' => '30');
   $day2[] = array('id' => 31, 'text' => '31');
   
  
  
  $years2 = array();

  $years2[] = array('id' => 2004, 'text' => '2006');
  $years2[] = array('id' => 2005, 'text' => '2007');
  $years2[] = array('id' => 2006, 'text' => '2008');
  $years2[] = array('id' => 2007, 'text' => '2009');
  $years2[] = array('id' => 2008, 'text' => '2010');
  $years2[] = array('id' => 2009, 'text' => '2011');
  $years2[] = array('id' => 2010, 'text' => '2012');
  $years2[] = array('id' => 2011, 'text' => '2013');
    

?>

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript" src="includes/general.js"></script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
        </table></td>
<!-- body_text //-->
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <form action="stats_batch_report.php" method=get>
          <tr>
            <td class="pageHeading" height="50"><?php echo HEADING_TITLE; ?></td>
           
          </tr>
          <tr>
          		
          		  <td  colspan="2"class="main" align="left"><b>Start : </b> <?=
'        Month: ' . tep_draw_pull_down_menu('month', $months, $month, 'onchange=\'this.form.submit();\'') .
'&nbsp;    Day: ' . tep_draw_pull_down_menu('day', $day, $day1, 'onchange=\'this.form.submit();\'') .
'&nbsp;   Year: ' . tep_draw_pull_down_menu('year', $years, $year, 'onchange=\'this.form.submit();\'')?><br><b>End : &nbsp;</b> 
            <?=
'        Month: ' . tep_draw_pull_down_menu('month2', $months2, $month22, 'onchange=\'this.form.submit();\'') .
'&nbsp;    Day: ' . tep_draw_pull_down_menu('day2', $day2, $day22, 'onchange=\'this.form.submit();\'') .
'&nbsp;   Year: ' . tep_draw_pull_down_menu('year2', $years, $year22, 'onchange=\'this.form.submit();\'')?>

            </td>
          </tr>


          <input type="hidden" name="by" value="<?=$HTTP_GET_VARS['by']?>">
          </form>
        </table></td>
      </tr></table>
      <table border="0" width="100%" cellspacing="0" cellpadding="2">
		<tr><td width="450" valign="top">
		
<table border="0" width="95%" cellspacing="2" cellpadding="2">

<tr  class="dataTableHeadingRow">

<td  class="dataTableHeadingContent" align='center' valign="bottom"><?php echo (ORDERID); ?></td>
<td  class="dataTableHeadingContent" align='center' valign="bottom"><?php echo (DATETIME); ?></td>
<td  class="dataTableHeadingContent" align='center' valign="bottom"><?php echo (CHARGETOTAL); ?></td>
<td class="dataTableHeadingContent" align='center' valign="bottom"><?php echo (CCTYPE); ?></td>
<td class="dataTableHeadingContent" align='center' valign="bottom"><?php echo (CCNUMBER); ?></td>

</tr>
		
<?php 
        
        //begin query 
        
		$batch_query_raw ="select ot.value, ot.title, ot.class, o.date_purchased, o.orders_id, o.cc_type, o.cc_number, o.payment_method  from ". TABLE_ORDERS . " o , " . TABLE_ORDERS_TOTAL . " ot where o.orders_id = ot.orders_id AND o.date_purchased between '" . $date1 . "' AND '" .$date2 ."'";
		$batch_query = tep_db_query($batch_query_raw);
		$total_accumulator = 0.00;
		$card1_accumulator = 0.00;
		$card2_accumulator = 0.00;
		$card3_accumulator = 0.00;
		$card4_accumulator = 0.00;
		$card5_accumulator = 0.00;
           $non_cc_accumulator = 0.00;
//		$loop=0;
		while ($orders = tep_db_fetch_array($batch_query)){
		  if ($orders['class']=='ot_total'){
		  	$total_accumulator += round($orders['value'],2) ;
		  	$loop +=1;
	  		if ($orders['payment_method']=='Credit Card'){
			    switch($orders[cc_type]){
				  case dbCARD1:
				  	$card1_accumulator += round($orders['value'],2) ;
				  	break;
				  case dbCARD2:
				  	$card2_accumulator += round($orders['value'],2);
				  	break;
				  case dbCARD3:
				  	$card3_accumulator += round($orders['value'],2);
					  break;
                         case dbCARD4:
				  	$card4_accumulator += round($orders['value'],2);
					  break;
				  default:
				  	$card5_accumulator += round($orders['value'],2) ; 	
				}
			    
			}
	  		else {
			    $non_cc_accumulator += round($orders['value'],2);
			}
			
			echo ('<tr class="dataTableRow">
<td class="dataTableContent" align="center">' . $orders['orders_id'] . '</td>
<td class="dataTableContent" align="center">' . $orders['date_purchased'] . '</td>
<td class="dataTableContent" align="center">$' . number_format(round($orders['value'],2),2) . '</td>
<td class="dataTableContent" align="center">' . $orders['cc_type'] . '</td>
<td class="dataTableContent" align="center">' . $orders['cc_number'] . '</td></tr>');
			
			//tep_href_link

			
			}
	  }

?>
		</table>
       </td>
	   <td valign="top">
<table >
<tr  class="dataTableHeadingRow" ><td  class="dataTableHeadingContent" width='70' align='right' valign="bottom"><?php echo CARD1 ?></td><td class="dataTableContent"  width='100' align='right'><?php echo ("$" . number_format($card1_accumulator,2)); ?></td></tr>
<tr  class="dataTableHeadingRow" ><td  class="dataTableHeadingContent" width='70' align='right' valign="bottom"><?php echo CARD2 ?></td><td class="dataTableContent"  width='100' align='right'><?php echo ("$" . number_format($card2_accumulator,2)); ?></td></tr>
<tr  class="dataTableHeadingRow" ><td  class="dataTableHeadingContent" width='70' align='right' valign="bottom"><?php echo CARD3 ?></td><td class="dataTableContent"  width='100' align='right'><?php echo ("$" . number_format($card3_accumulator,2)); ?></td></tr>
<tr  class="dataTableHeadingRow" ><td  class="dataTableHeadingContent" width='70' align='right' valign="bottom"><?php echo CARD4 ?></td><td class="dataTableContent"  width='100' align='right'><?php echo ("$" . number_format($card4_accumulator,2)); ?></td></tr>
<tr  class="dataTableHeadingRow" ><td  class="dataTableHeadingContent" width='70' align='right' valign="bottom"><?php echo CARD5 ?></td><td class="dataTableContent"  width='100' align='right'><?php echo ("$" . number_format($card5_accumulator,2)); ?></td></tr>
<tr  class="dataTableHeadingRow" ><td  class="dataTableHeadingContent" width='70' align='right' valign="bottom"><?php echo NOTCARD ?></td><td class="dataTableContent"  width='100' align='right'><?php echo ("$" . number_format($non_cc_accumulator,2)); ?></td></tr>
<tr  class="dataTableHeadingRow" ><td  class="dataTableHeadingContent" width='70' align='right' valign="bottom">TOTAL</td><td class="dataTableContent"  width='100' align='right'><?php echo ("$" . number_format($total_accumulator,2)); ?></td></tr>
	   
	   
	   </table>
	   </td>
	   </tr>

    </table></td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>